package top.gokzzz.log.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Index;
import javax.persistence.Lob;
import javax.persistence.Table;

/**
 * 系統持久化實體審計日誌
 *
 * @author Gok
 * @version 1.0
 */
@Entity
@Table(name = "SYS_DOMAIN_LOG", indexes = {
        @Index(name = "IDX_PRIMARY_KEY", columnList = "PRIMARY_KEY"),
        @Index(name = "IDX_ACTION", columnList = "ACTION"),
        @Index(name = "IDX_TABLE_NAME", columnList = "TABLE_NAME")
})
public class SysDomainLog extends BaseEntity{
    private static final long serialVersionUID = 3013377048421913752L;

    public SysDomainLog() {}

    public SysDomainLog(String primaryKey, Action action, String tableName, String data) {
        this.primaryKey = primaryKey;
        this.action = action;
        this.tableName = tableName;
        this.data = data;
    }

    public enum Action{
        INSERT,UPDATE,DELETE
    }

    /**
     * 主鍵
     */
    @Column(name = "PRIMARY_KEY", length = 64)
    private String primaryKey;

    /**
     * 操作行為
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "ACTION", length = 10,nullable = false)
    private Action action;

    /**
     * 表名
     */
    @Column(name = "TABLE_NAME",nullable = false)
    private String tableName;

    /**
     * 數據記錄快照
     */
    @Lob
    @Column(name = "DATA")
    private String data;

    public String getPrimaryKey() {
        return primaryKey;
    }

    public void setPrimaryKey(String primaryKey) {
        this.primaryKey = primaryKey;
    }

    public Action getAction() {
        return action;
    }

    public void setAction(Action action) {
        this.action = action;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

}
